/**
 * 
 */
package ac.svn.accesscontrol.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import ac.svn.accesscontrol.utils.UIUtility;

/**
 * @author Enigmanic
 *
 */
public class AccessUnitListCell extends JPanel {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private JCheckBox readCheckBox;
    private JCheckBox writeCheckBox;
    private JLabel titleLabel;
    private static Font selectedFont;
    private static Font defFont;
    public AccessUnitListCell()
    {
	super(new BorderLayout(5,0),true);
	initComponents();
    }


    private void initComponents() 
    {

	setBackground(Color.WHITE);
	UIUtility.setAllShadowedBorder(this);
	//setBorder(new DropShadowBorder());

	titleLabel = new JLabel();
	readCheckBox = new JCheckBox("R", true);
	readCheckBox.setBackground(Color.WHITE);
	writeCheckBox= new JCheckBox("W", false);
	writeCheckBox.setBackground(Color.WHITE);

	JPanel  panel = new JPanel((new GridLayout(1, 2, 0, 3)),true);

	panel.setBackground(Color.WHITE);
	
	panel.add(readCheckBox);
	panel.add(writeCheckBox);

	add(titleLabel,BorderLayout.CENTER );
	add(panel,BorderLayout.EAST);

	if(null == selectedFont )
	{
	    initFont();
	}
    }

    private void initFont() {
	defFont = titleLabel.getFont();
	selectedFont = new Font(defFont.getFamily(),Font.BOLD,defFont.getSize()+2);
    }


    public void setIcon(Icon icon )
    {
	titleLabel.setIcon(icon);
    }

    public void setTitle(String title)
    {
	titleLabel.setText(title);
    }

    public void setAccess(boolean r,boolean w)
    {
	readCheckBox.setSelected(r);
	writeCheckBox.setSelected(w);
    }

    public boolean getRead()
    {
	return readCheckBox.isSelected();
    }

    public boolean getWrite()
    {
	return writeCheckBox.isSelected();
    }

    public void setSelected(boolean b)
    {
	if(b)
	{
	    setFont(selectedFont);
	}
	else
	{
	    setFont(defFont);
	}
    }


}
